<?php
	require("libraries/agency.php");
	class Ordership extends Agency{
		protected $_user = "";
		public function __construct(){
			parent::__construct();
			$this->load->model("model_ordership");
			$this->_user = $this->session->userdata('ses_userid');
		}
		public function index(){
			$id = $this->uri->segment(4);
			if($id == NULL){die("page not found");}
			$listcrs = $this->listcruis($this->_user);
			$users = array();
			foreach($listcrs as $cruise){
				$users[] = $cruise['cruises_id'];
			}
			if(!in_array($id,$users)){
				die("Page not found");
			}
			$data['listall'] = $this->listcruis($this->_user);
			$config['base_url'] = base_url().'agency/ordership/index/';
			$config['total_rows'] = $this->model_ordership->count_all($id);
			$config['per_page'] = 10;
			$config['uri_segment'] = 4;
			$this->load->library("pagination");
			$this->pagination->initialize($config); 
			$start = $this->uri->segment(4);
			$data['title']= "Manage booking";
			$data['data']['info']= $this->model_ordership->listorder($id,$config['per_page'],$start);
			$data['cruiseid'] = $id;
			$data['act'] = 1;
			$data['template'] = "ordership/list_order";
			$this->load->view("layout",$data);
		}
		public function listall(){
			$data['data'] = "haanhdon";
			$data['act'] = 1;
			$listcrs = $this->listcruis($this->_user);
			$data['listall'] = $this->listcruis($this->_user);
			$data['title']= "Manage booking";
			$data['template'] = "ordership/listall";
			$this->load->view("layout",$data);
		}
		public function order_view(){
			$id = $this->uri->segment(4);
			$data['title']= "View booking";
			$data['template'] = "ordership/order_view";
			$data['data'] = "";
			$data['all'] = $this->model_ordership->order_view($id);	
			if($data['all'] == NULL){
				die("error!");
			}
			$val = array("order_status"=> "1");
			$data['act'] = 1;
			//$this->model_ordership->update_status($val,$id);
			$this->load->view("layout",$data);		
		}
        public function active(){
            $id   	= $this->uri->segment(4);
            $status	= $this->uri->segment(5);
			$cruise = $this->uri->segment(6);
            $db = array(
                "order_status" => $status
            );
            $this->model_ordership->update_status($db,$id);
            redirect(base_url()."agency/ordership/index/".$cruise);
        }
		public function del(){
			$id = $this->uri->segment(4);
			$cruise = $this->uri->segment(5);
			$this->model_ordership->del($id);
			redirect(base_url()."agency/ordership/index/".$cruise);
		}
	}